package servlets;

import java.io.IOException;
import java.util.LinkedList;
import java.util.List;

import javax.jdo.PersistenceManager;
import javax.jdo.Query;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import bean.Member;
import bean.MemberAdm;

import pmf.PMF;

@SuppressWarnings("serial")
public class IndexServlet extends HttpServlet {
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		
		req.getRequestDispatcher("./index.jsp").forward(req, resp);
	}
	
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		
		MemberAdm memAdm = new MemberAdm();
		Member saveMem = memAdm.logIn(req.getParameter("memID"), req.getParameter("memPSW"));
		
		if(null==saveMem){
			resp.sendRedirect("./index");
		}else{
		
		HttpSession session = req.getSession();
		session.setAttribute("userID", saveMem.getUserID());
		session.setAttribute("password", saveMem.getPassword());
		session.setAttribute("key", saveMem.getKey());
		session.setAttribute("id", saveMem.getKey().getId());
		session.setAttribute("state", saveMem.isState());
		session.setAttribute("name", saveMem.getName());
		
		resp.sendRedirect("./index");
		}
	}
}
